<?php
function htmlspec($src) {
	return htmlspecialchars($src, ENT_COMPAT, 'UTF-8');
}

function make_tag_links($str_tags, $blg_uri) {
	if(strlen($str_tags) == 0) {
		return '';
	}
	$arr_tags = explode(' ', $str_tags);
	$rt = '';
	foreach($arr_tags as $tag) {
		$rt .= '<a href="/' . $blg_uri . '/tag/' . urlencode($tag) . '" rel="tag">' . htmlspec($tag) . '</a> ';
	}
	return $rt;
}

function date_part($str_datetime) {
	$dp = date_parse($str_datetime);
	return $dp['month'] . '/' . $dp['day'] . '/' . $dp['year'];
}

function get_avatar_name($user_id) {
	$fn = $_SERVER['DOCUMENT_ROOT'] . '/img/avatars/avt_' . $user_id . '_48x48.jpg';
	if(file_exists($fn)) {
		return 'avt_' . $user_id . '_48x48.jpg';
	} else {
		return 'avt_-1_48x48.jpg';
	}
}

function entry_state_indicator($entry_state, $smaller = FALSE) {
	$r = ' ';
	switch($entry_state) {
		case 0:
			$r .= 'secret';
			break;
		case 3:
			$r .= 'community';
			break;
		case 99:
			$r .= 'draft';
			break;
		default:
			$r = '';
			break;
	}
	if($smaller && (strlen($r) >= 1)) {
		$r .= '_small';
	}
	return $r;
}
?>
